﻿#region Copyright(C) 2011 NCS Pte. Ltd. All rights reserved.

// ==============================================================================
// Copyright(C) 2011 NCS Pte Ltd
//
// SYSTEM NAME			: MOH Online Collaboration Portal
// COMPONENT ID			: NCS.OCP.SharePointComponent.Layouts.SharePointComponent.viewSlideshow
// COMPONENT DESC		: Slideshow fun work album pic.
//
// CREATED DATE/BY	    : 10-08-2011 / Zhang Zu Meng
//
// REVISION HISTORY     :
// DATE/BY  ISSUE#/SR#/CS/PM#/OTHERS    DESCRIPTION OF CHANGE
// 
// ==============================================================================

#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using JM.JCY.Proxy;
using JM.JCY.BusinessEntity;
using JM.JCY.Common;
using System.Data;
using JM.JCY.Common.Utilities;

namespace WebApplicationTestShowPic
{
    public partial class viewSlideshow : System.Web.UI.Page
    {
        public int _albumId
        {
            get;
            set;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.UrlReferrer != null)
                {
                    this.LinkButtonBacktoAlbum.PostBackUrl = Request.UrlReferrer.PathAndQuery;
                }
                if (Request.QueryString["AlbumId"] != null)
                {
                    this.llPlayCount.Text = "2000";
                    _albumId = Int32.Parse(Request.QueryString["AlbumId"].ToString());
                    LoadAlbumContent(_albumId);
                }
            }
        }

        private void LoadAlbumContent(int AlbumId)
        {
           PhotoAlbumSearchDataSet.T_AlbumContentDataTable AlbumContentDT;
           using (PhotoAlbumProxy proxy = new PhotoAlbumProxy())
            {
                //get album data
                AlbumContentDT = proxy.GetAlbumContents(_albumId);
                if (AlbumContentDT.Rows.Count > 0)
                {

                    string albumName = AlbumContentDT[0].AlbumName;
                    albumName = albumName.Substring(0, albumName.Length > 30 ? 30 : albumName.Length);
                    this.HiddenAlbumname.Value = albumName;
                    DataView dv = AlbumContentDT.DefaultView;
                    dv.Sort = "LAST_UPDATED_TIME desc";

                    string query = "";
                    for (int i = 0; i < dv.ToTable().Rows.Count; i++)
                    {
                        if (i != dv.ToTable().Rows.Count - 1)
                        {
                            query += "[" + "'" + dv.ToTable().Rows[i]["OptimizeImgUrl"].ToString() + "','" + dv.ToTable().Rows[0]["AlbumName"].ToString() + "','" + dv.ToTable().Rows[i]["Description"].ToString() + "','" + dv.ToTable().Rows[i]["StaffId"].ToString() + "','" + dv.ToTable().Rows[i]["CREATED_BY"].ToString() + "'],";
                        }
                        else
                            query += "[" + "'" + dv.ToTable().Rows[i]["OptimizeImgUrl"].ToString() + "','" + dv.ToTable().Rows[0]["AlbumName"].ToString() + "','" + dv.ToTable().Rows[i]["Description"].ToString() + "','" + dv.ToTable().Rows[i]["StaffId"].ToString() + "','" + dv.ToTable().Rows[i]["CREATED_BY"].ToString() + "']";
                    }

                    query = "[" + query + "]";
                    this.llArrows.Text = query;
                }
            }
        }
    }
}